<template>
    <div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="id" label="序号" width="200">
            </el-table-column>
            <el-table-column prop="name" label="岗位名称" width="200">
            </el-table-column>
            <el-table-column prop="salary_down" label="底薪" width="200">
            </el-table-column>
            <el-table-column prop="salary_up" label="最高薪水" width="200">
            </el-table-column>
            <el-table-column prop="tel" label="联系电话" width="200">
            </el-table-column>
            <el-table-column prop="intro" label="岗位介绍" width="200">
            </el-table-column>
            <el-table-column label="公司" width="250">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="find(scope.$index)"
                    >公司详情
                    </el-button
                    >

                    <el-dialog
                            title="提示"
                            :visible.sync="dialogVisible1"
                            width="30%"


                    >
            <span>

                <div style="display:inline">
                <label>公司名称</label>
                <el-input
                        v-model="form_new.name"
                        style="margin-right: 40%;padding-bottom: 10px"
                ></el-input>
                
             
                <label>公司行业</label>
                <el-input
                        v-model="form_new.industry"
                        style="margin-right: 40% ;argin-top: 10px"
                ></el-input>
               
               
                <label>人员规模</label>
                <el-input
                        v-model="form_new.size"
                        style="margin-right: 40%"
                ></el-input>
               
             
                <label>联系电话</label>
                <el-input
                        v-model="form_new.tel"
                        style="margin-right: 40%"
                ></el-input>
               
              
                <label>公司评分</label>
                <el-input
                        v-model="form_new.grade"
                        style="margin-right: 40%"
                ></el-input>
                </div>
             
             
            </span>
                        <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible1 = false">取 消</el-button>
              <el-button type="primary" @click="dialogVisible1 = false"
              >确 定</el-button
              >
            </span>
                    </el-dialog>
                </template>
            </el-table-column>

            <el-table-column label="部门" width="300">
                <template slot-scope="scope">
                    <el-button type="warning" size="mini" @click="find1(scope.$index)"
                    >部门详情
                    </el-button
                    >
                    <el-dialog
                            title="提示"
                            :visible.sync="dialogVisible2"
                            width="30%"

                    >
            <span>
             
              <div style="display:inline">
                <label>部门名称</label>
                <el-input
                        v-model="form.name"
                        style="margin-right: 40%;padding-bottom: 10px"
                ></el-input>
                
             
                <label>部门介绍</label>
                <el-input
                        v-model="form.intro"
                        style="margin-right: 40%;margin-top: 10px"
                ></el-input>
               
               
                </div>
             
             
            </span>
                        <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible2 = false">取 消</el-button>
              <el-button type="primary" @click="dialogVisible2 = false"
              >确 定</el-button
              >
            </span>
                    </el-dialog>
                </template>
            </el-table-column>

            <el-table-column label="投递简历" width="250">
                <template slot-scope="scope">
                    <el-button :type="scope.row.tag=='已申请过该职位'? 'info' : 'danger'" size="mini"
                               @click="find2(scope.$index)">{{scope.row.con}}
                    </el-button>

                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "RecMar",
        data() {
            return {
                rec: {
                    uid: "",
                    wid: "",
                    status: "",
                },
                tableData: [],
                companys: [],
                departments: [],
                form_new: {
                    id: "",
                    name: "",
                    industry: "",
                    size: "",
                    grade: "",
                    tel: "",
                },
                form: {

                    name: "",
                    intro: "",
                },
                dialogVisible1: false,
                dialogVisible2: false,
            };
        },
        created() {
            this.getRequest("/rec/mar/get").then((data) => {
                //   console.log(data.data);
                if (data) {
                    // console.log(data.data.wanteds);

                    data.data.wanteds.forEach((item) => {

                        this.tableData.push({
                            id: item.id,
                            name: item.name,
                            salary_down: item.salaryDown,
                            salary_up: item.salaryUP,
                            tel: item.tel,
                            intro: item.intro,
                            status: item.status,
                            tag: "",
                            con: "投递",
                        });
                        this.companys.push(item.company);
                        this.departments.push(item.department);

                    });
                    // console.log(this.companys);
                    // console.log(this.departments);
                }
            });
        },
        methods: {
            handleEdit(index, row) {
                // console.log(index, row);
            },
            handleClose(done) {
                this.$confirm("确认关闭？")
                    .then((_) => {
                        done();
                    })
                    .catch((_) => {
                    });
            },
            find(index) {
                // console.log(index);
                this.dialogVisible1 = true;
                // console.log(this.companys);

                this.form_new.name = this.companys[index].name;
                this.form_new.industry = this.companys[index].industry;
                this.form_new.grade = this.companys[index].grade;
                this.form_new.tel = this.companys[index].tel;
                this.form_new.size = this.companys[index].size;
            },
            find1(index) {
                // console.log(index);
                this.dialogVisible2 = true;
                // console.log(this.companys);
                // console.log(this.departments[index].intro);
                this.form.name = this.departments[index].name;
                this.form.intro = this.departments[index].intro;
            },
            find2(index) {

                this.rec.uid = JSON.parse(window.sessionStorage.getItem("uid"));
                // console.log(this.tableData);
                this.rec.wid = this.tableData[index].id;
                this.rec.status = "待审核";
                // console.log(this.rec);

                this.axios({
                    url: '/rec/modify',
                    method: 'post',
                    params: {'uid': this.rec.uid, 'wid': this.rec.wid, 'status': this.rec.status},
                })
                    .then((res) => {

                        this.$message.success(res.msg);
                    }).catch((error) => {

                    this.tableData[index].tag = '已申请过该职位';
                    this.tableData[index].con = '已投递';

                    // console.log(this.tableData);
                    this.$message.error("上传失败");
                    //alert("无法展示");

                });

            }
        },
    };
</script>

<style scoped>
</style>